

%fb_ind2=(fill_holes_in_binary_vec(abs(velM)>0.001,150))+2*(fill_holes_in_binary_vec(abs(velP)>0.001,150))+1;
% 1 = no mov no vis
% 2 = just vis
% 3 = just mov
% 4 = mov & vis

roi_act=map_ROI_act_to_aux_data(ROIs(sel_roi).activity,frame_times,length(aux_data));
% remove points where we have no information, i.e. roi_act=0
fb_ind=[0 fb_ind2]'.*abs(sign(roi_act));

roi_act=map_ROI_act_to_aux_data(ROIs(sel_roi).activity,frame_times,length(aux_data));
droi_act=[diff(roi_act)' 0];
droi_act(droi_act<0)=0;

seg_ind=[find(diff(fb_ind))+1];
cnt=zeros(4,1);
fb_seg_act=cell(4,1);
tmp_case_mem=0;
for ind=1:length(seg_ind)-1
    tmp_case=fb_ind(seg_ind(ind));
    cnt(tmp_case)=cnt(tmp_case)+1;
    fb_seg_act{tmp_case}(cnt(tmp_case),1)=mean(roi_act(seg_ind(ind):seg_ind(ind+1)-1));
    fb_seg_act{tmp_case}(cnt(tmp_case),2)=seg_ind(ind+1)-seg_ind(ind);
    fb_seg_act{tmp_case}(cnt(tmp_case),3)=tmp_case_mem;
    tmp_case_mem=tmp_case;
end

fb_act=zeros(4,3);
for ind=1:4
    fb_act(ind,1)=mean(roi_act(find(fb_ind==ind)));
    fb_act(ind,2)=std(roi_act(find(fb_ind==ind)));
    fb_act(ind,3)=mean(droi_act(find(fb_ind==ind)));
end

% rand_fb_act=zeros(500,4);
% for knd=1:500
%     tmp_act=circshift(roi_act,ceil(rand*length(roi_act)));
%     for ind=1:4
%         rand_fb_act(knd,ind)=mean(tmp_act(find(fb_ind==ind)));
%     end
% end


figure(101);
clf; hold on
plot(fb_act(:,1),'ko','linewidth',2)
plot(fb_act(:,1)+fb_act(:,2),'ro');
plot(fb_act(:,1)-fb_act(:,2),'ro');
% plot(mean(rand_fb_act),'k')
title(['Cell nr. ' num2str(sel_roi) '  - F'])

figure(102);
clf;hold on
for ind=1:4
    plot(ind,sum(fb_seg_act{ind}(:,1).*fb_seg_act{ind}(:,2))/sum(fb_seg_act{ind}(:,2)),'ko','linewidth',2);
end
title(['Cell nr. ' num2str(sel_roi) '  - F'])

figure(103);
clf;
plot(fb_act(:,3),'ko','linewidth',2)
title(['Cell nr. ' num2str(sel_roi) '  - Delta F'])


